<?php
/**
 * Created by PhpStorm.
 * User: MRPHAN
 * Date: 9/21/2014
 * Time: 9:05 PM
 */
namespace Backend\Modules\Video\Forms;


use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\TextArea;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Forms\Element\Check;
use Phalcon\Forms\Element\Radio;
use Phalcon\Forms\Element\File;
use Phalcon\Forms\Element\Select;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Email;
use Phalcon\Validation\Validator\Identical;
use Phalcon\Validation\Validator\StringLength;
use Phalcon\Validation\Validator\Confirmation;
use Phalcon\Validation\Validator\Between;
use Phalcon\Forms\Element\Submit;
use Backend\Modules\Video\Models\National;
class FormCreateArtist extends Form{

    public function initialize($entity = null , $options = null){

        /*
         * Artist Id
         */

        $id = new Hidden('id');
        $this->add($id);

        /*
         * Avatar
         */
        $file = new File('file' , array(
            'id' => 'fileupload'
        ));
        $file->setLabel('Hình đại diện');
        $this->add($file);
        /*
         *
         * Artist Type
         */
        $artist_type = new Select('artist_type',
            array(
                '1' => 'Diễn Viên' ,
                '2' => 'Đạo Diễn'
            ));
        $artist_type->setLabel('Loại');
        $artist_type->addValidator(new PresenceOf(array(
            'message' => 'Type is required'
        )));
        $this->add($artist_type);

        /*
         * Artist Name
         */
        $name = new Text('name',array(
            'class' => 'forms-control col-xs-12'
        ));
        $name->setLabel('Tên');
        $name->addValidators(array(
            new PresenceOf(array(
                'message' => 'Name is required'
            ))
        ));
        $this->add($name);

        /*
         * Artist National
         */
        $national = new Select('national_id' , National::find() ,
            array('using' =>
                array('id' , 'name') ,
                    'useEmpty' => true ,
                    'emptyText' => 'Chọn quốc gia' ,
                    'emptyValue' => 0 ,
                    'class' => 'forms-control col-xs-12'
            ) );
        $national->setLabel('Quốc Gia');
        $this->add($national);

        /*
         * Artist Gender
         */
        $gender = new Select('gender',
            array(
                '1' => 'Nữ',
                '2' => 'Nam',
                '3' => 'Khác' ,
            ),
           array('using' =>
                array('id' , 'name') ,
                    'useEmpty' => true ,
                    'emptyText' => 'Chọn giới tính' ,
                    'emptyValue' => 0 ,
                    'class' => 'forms-control col-xs-12'
            ) 
        );
        $gender->setLabel('Giới Tính');
        $gender->addValidator(new PresenceOf(array(
            'message' => 'Gender is required'
        )));
        $this->add($gender);

        /*
         * Artist Info
         */
        $info = new TextArea('info' , array(
            'class' => 'forms-control col-xs-12',
            'row'   => '10'
        ));
        $info->setLabel('Thông tin chung');
        $this->add($info);

        /*
         * Artist BOD
         */
        $bod = new Text('bod',array(
            'class' => 'forms-control col-xs-12',
            'value' => date('Y-m-d')

        ));
        $bod->setLabel('Ngày Sinh');
        $bod->addValidators(array(
            new PresenceOf(array(
                'message' => 'Bod is required'
            ))
        ));
        $this->add($bod);
        // CSRF
        $csrf = new Hidden('csrf');

        $csrf->addValidator(new Identical(array(
            'value' => $this->security->getSessionToken(),
            'message' => 'CSRF validation failed'
        )));

        $this->add($csrf);

        // Sign Up
        $this->add(new Submit('Add', array(
            'class' => 'btn btn-primary'
        )));
    }
    public function messages($name)
    {
        if($this->getMessagesFor($name))
        {
            foreach ($this->getMessagesFor($name) as $message)
            {
                $this->flash->error($message);
            }
        }
    }
}